﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Linq.Expressions;
using EfSearchModel.Model;

namespace QuickApp.Core
{
    /// <summary>
    /// 数据仓储模式（Repository）的接口，一种用来封装存储，读取和查找行为的机制，它模拟了一个对象集合
    /// </summary>
    /// <typeparam name="T">实体数据</typeparam>
    public interface IRepository<T> where T : class
    {
        /// <summary>
        /// 添加实体数据
        /// </summary>
        /// <param name="entity">实体数据</param>
        void Insert(T entity);

        /// <summary>
        /// 更新实体数据
        /// </summary>
        /// <param name="entity">实体数据</param>
        void Update(T entity);

        /// <summary>
        /// 删除指定Id的实体数据
        /// </summary>
        /// <param name="Id">实体Id</param>
        void Delete(string Id);

        /// <summary>
        /// 删除实体数据
        /// </summary>
        /// <param name="entity">实体数据</param>
        void Delete(T entity);

        /// <summary>
        /// 批量删除指定过滤表达式的实体数据列表
        /// </summary>
        /// <param name="predicate">过滤表达式</param>
        void DeleteAll(Expression<Func<T, bool>> predicate);

        /// <summary>
        /// 批量删除实体数据
        /// </summary>
        /// <param name="entities">实体数据列表</param>
        void DeleteAll(IEnumerable<T> entities);

        /// <summary>
        /// 获得指定Id的实体数据
        /// </summary>
        /// <param name="Id">实体Id</param>
        /// <returns>数据实体</returns>
        T Find(string Id);

        /// <summary>
        /// 获取指定指定过滤表达式的单个实体数据
        /// </summary>
        /// <param name="predicate">过滤表达式</param>
        /// <returns>数据实体</returns>
        T Find(Func<T, Boolean> predicate);

        /// <summary>
        /// 获取指定指定过滤表达式的实体数据列表
        /// </summary>
        /// <param name="predicate">过滤表达式</param>
        /// <returns>数据实体列表</returns>
        IQueryable<T> FindAll(Expression<Func<T, bool>> predicate = null);

        /// <summary>
        /// 获取指定搜索条件的数据分页实体
        /// </summary>
        /// <param name="pageInfo">分页信息</param>
        /// <param name="query">搜索条件</param>
        /// <returns>数据分页实体</returns>
        IPageable<T> GetPageable(PageInfo pageInfo, QueryModel query);
    }
}
